package cn.itcast.health.admin.controller;

import cn.itcast.health.admin.logs.OperationLog;
import cn.itcast.health.commons.entity.QueryPageBean;
import cn.itcast.health.commons.entity.Result;
import cn.itcast.health.commons.utils.LogUtils;
import cn.itcast.health.interfaces.service.CheckGroupService;
import cn.itcast.health.interfaces.service.CheckitemService;
import cn.itcast.health.pojo.CheckGI;
import cn.itcast.health.pojo.CheckGroup;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @Reference
    private CheckitemService checkitemService;
    @Reference
    private CheckGroupService checkGroupService;

    @GetMapping("/findCheckitemAll.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "供检查组添加数据时所需要的检查项的数据")
    public Result findCheckitemAll(){
        Result result = checkitemService.findCheckitemAll();
        return result;
    }

    @PostMapping("/addCheckGroupAndCheckGroupCheckitem.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.ADD, operationContent = "添加检查组及检查组与检查项中间表的数据")
    public Result addCheckGroupAndCheckGroupCheckitem(@RequestBody CheckGI checkGI){
        Result result = checkGroupService.addCheckGroupAndCheckGroupCheckitem(checkGI);
        return result;
    }


    @GetMapping("/findByPageCheckGroupData.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "检查组的分页查询数据")
    public Result findByPageCheckGroupData(QueryPageBean queryPageBean){
        Result result = checkGroupService.findByPageCheckGroupData(queryPageBean);
        return result;
    }


    @GetMapping("/findByIdCheckitemAnaIdsData.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.QUERY, operationContent = "供检查组组修改时所需要的检查项及检查组与检查项中间表的所选的数据")
    public Result findByIdCheckitemAnaIdsData(CheckGroup checkGroup){
        Result result = checkGroupService.findByIdCheckitemAnaIdsData(checkGroup);
        return result;
    }


    @PutMapping("/updateCheckGroupAndCheckGroupCheckitemData.do")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.MODIFY, operationContent = "修改检查组及检查组与检查项中间表的数据")
    public Result updateCheckGroupAndCheckGroupCheckitemData(@RequestBody CheckGI checkGI){
        Result result = checkGroupService.updateCheckGroupAndCheckGroupCheckitemData(checkGI);
        return result;
    }

    @DeleteMapping("/deleteByIdCheckGroupData.do")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @OperationLog(moduleName = LogUtils.Module.SYSTEM, operationType = LogUtils.Type.DELETE, operationContent = "逻辑删除检查组的数据")
    public Result deleteByIdCheckGroupData(@RequestBody CheckGroup checkGroup){
        Result result = checkGroupService.deleteByIdCheckGroupData(checkGroup.getId());
        return result;
    }
}
